﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace eTerm.NetSocket
{
    public sealed class eTermDDN350Socket:BaseTermSocket
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="eTermDDN350Socket"/> class.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="port">The port.</param>
        /// <param name="rid">The rid.</param>
        /// <param name="sid">The sid.</param>
        /// <param name="localPoint">The local point.</param>
        public eTermDDN350Socket(string address,int port,byte rid,byte sid, string localPoint):base(address,port,false,string.Empty,string.Empty,rid,sid,localPoint) { }

        /// <summary>
        /// Logs the in.
        /// </summary>
        protected override void LogIn()
        {
            SendStream(AddressPacket());
        }


        /// <summary>
        /// 地址认证首发包.
        /// </summary>
        /// <returns></returns>
        private byte[] AddressPacket()
        {
            List<byte> items = new List<byte>(){ 
                0x01,0xA2,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x00,0x00,0x00,0x00,0x00,0x00
               ,0x00,0x00,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x00,0x00,0x00,0x00,0x00,0x00
               ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
               ,0x00,0x00,0x30,0x30,0x30,0x33,0x66,0x66,0x64,0x62,0x65,0x62,0x65,0x62
            };
            byte[] IpAddress = Encoding.Default.GetBytes((LocalEP as IPEndPoint).Address.ToString());
            int ipLength = IpAddress.Length;
            items.AddRange(IpAddress);
            while (ipLength++ < 15)
                items.Add(0x20);
            items.AddRange(new byte[]{
                0x00,0x00,0x00
               ,0x00,0x33,0x31,0x30,0x00,0x30,0x30,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,0x00 
               ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
               ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
               ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
               ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
               ,0x00,0x00
               
            });
            return items.ToArray();
        }



    }
}
